<?php

class Admin_Model extends Model
{
	function Admin()
	{
		parent::Model();
	}

	public function getTaskCount()
	{
		$sql = "SELECT count(task_id) AS count FROM enctask";
		$query = $this->db->query($sql);
		return $query->row()->count;		
	}
	
	public function getTagCount()
	{
		$sql = "SELECT count(tag_id) AS count FROM tag";
		$query = $this->db->query($sql);
		return $query->row()->count;		
	}
	
	public function getTaskTagCount()
	{
		$sql = "SELECT count(id) AS count FROM task_tag";
		$query = $this->db->query($sql);
		return $query->row()->count;		
	}
	
	public function getUserCount()
	{
		$sql = "SELECT count(user_id) AS count FROM user";
		$query = $this->db->query($sql);
		return $query->row()->count;		
	}
	
	public function getSessionCount($onlyActive = true)
	{
		$sess_expire = (int)$this->config->item('sess_expire');
		
		$sql = "SELECT count(session_id) AS count FROM ci_sessions ";
		
		$sql .= $onlyActive ? "WHERE last_activity + $sess_expire < NOW()" : '';
		
		//log_message('info', $sql);
		
		$query = $this->db->query($sql);
		return $query->row()->count;
	}
	
	public function getBugReportsCount($onlyActive = true)
	{
		$sql = "SELECT count(bug_id) AS count FROM bug_reports";
		$query = $this->db->query($sql);
		return $query->row()->count;
	}
	
}